package org.jeecg.modules.demo.baseselfordercommodity.controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.demo.baseselfordercommodity.entity.BaseSelfOrderCommodity;
import org.jeecg.modules.demo.baseselfordercommodity.service.IBaseSelfOrderCommodityService;
import org.jeecg.modules.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 自提订单商品表
 * @Author: jeecg-boot
 * @Date: 2022-02-11
 * @Version: V1.0
 */
@Api(tags = "自提订单商品表")
@RestController
@RequestMapping("/baseselfordercommodity/baseSelfOrderCommodity")
@Slf4j
public class BaseSelfOrderCommodityController extends JeecgController<BaseSelfOrderCommodity, IBaseSelfOrderCommodityService> {

    @Autowired
    private IBaseSelfOrderCommodityService baseSelfOrderCommodityService;
    @Autowired
    private RedisUtils redisUtils;

//	@GetMapping(value = "/list")
//    public Result<?> queryPageList(@RequestParam(name = "memberName", required = false) String memberName,
//                                   @RequestParam(name = "orderCode", required = false) String orderCode,
//                                   @RequestParam(name = "memberPhone", required = false) String memberPhone,
//                                   @RequestParam(name = "startDate", required = false) String startDate,
//                                   @RequestParam(name = "endDate", required = false) String endDate,
//                                   @RequestParam(name = "status", required = false) String status,
//                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
//                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
//                                   HttpServletRequest req) {
//        String token = TokenUtils.getTokenByRequest(req);
//        String storeId = (String) redisUtils.get(RedisUtils.storeId +token);
//        if(oConvertUtils.isEmpty(storeId)){
//            return Result.error("请先到首页选择店铺");
//        }
//        if (storeId.contains("过期")) {
//            return Result.error("店铺已过期，续费后才可操作");
//        }
//        Page<Map<String, Object>> page = new Page<>(pageNo, pageSize);
//		IPage<Map<String, Object>> pageList = baseSelfOrderCommodityService.listSelfOrder(page, storeId, memberName, orderCode, memberPhone, startDate, endDate, status);
//		List<Map<String, Object>> records = pageList.getRecords();
//		records.forEach(m -> {
//			BigDecimal totalPrice = m.get("totalPrice") == null ? BigDecimal.ZERO : new BigDecimal(String.valueOf(m.get("totalPrice")));
//			BigDecimal preferAmount = m.get("preferAmount") == null ? BigDecimal.ZERO : new BigDecimal(String.valueOf(m.get("preferAmount")));
//			m.put("realPrice", totalPrice.subtract(preferAmount));
//			String status1 = String.valueOf(m.get("status"));
//			if ("0".equals(status1)) {
//				m.put("statusName", "未自提");
//			} else if ("1".equals(status1)) {
//				m.put("statusName", "已自提");
//			}
//		});
//		return Result.OK(pageList);
//    }
//
//	@PutMapping(value = "/pickUp")
//	public Result<?> pickUp(@RequestParam("id") String id) {
//		BaseSelfOrderCommodity bsoc = baseSelfOrderCommodityService.getById(id);
//		if ("0".equals(bsoc.getStatus())) {
//			bsoc.setStatus("1");
//			bsoc.setPickUpTime(new Date());
//			baseSelfOrderCommodityService.updateById(bsoc);
//		}
//		return Result.OK("自提成功");
//	}
//
//	 @PutMapping(value = "/pickUpBatch")
//	 public Result<?> pickUpBatch(@RequestParam("ids") String ids) {
//		 List<String> idList = Arrays.asList(ids.split(","));
//		 for (String id : idList) {
//			 BaseSelfOrderCommodity bsoc = baseSelfOrderCommodityService.getById(id);
//			 if ("0".equals(bsoc.getStatus())) {
//				 bsoc.setStatus("1");
//				 bsoc.setPickUpTime(new Date());
//				 baseSelfOrderCommodityService.updateById(bsoc);
//			 }
//		 }
//		 return Result.OK("自提成功");
//	 }
}
